package com.yit.cn;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

/**
 * Created by zhangyanfei on 2019/4/21.
 *
 * @author zhangyanfei
 * @date 2019/04/21
 */
public class SchedulingContext {

    public static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    private static final String BOUNDARY_DATE = "2019-4-19";

    public static final int threshold = 11;

    public boolean isFly;

    /**
     * 行程距离 km
     */
    private double distance = 4.7;

    /**
     * 行程日期
     */
    private Date date;

    /**
     * A累计飞行天数
     */
    public int grandTotalDaysOfA;

    /**
     * A几天没飞了
     */
    public int restOfA;

    // 默认 A先飞
    private boolean normalACanFly = true;

    private boolean normalBCanFly = false;

    public boolean isBrest() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int days = calendar.get((Calendar.DAY_OF_MONTH));
        if (days == 18 || days == 19) {
            return true;
        }
        return false;
    }

    public int getRestOfA() {
        return restOfA;
    }

    public void setRestOfA(int restOfA) {
        this.restOfA = restOfA;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getAirplaneModel() {
        try {
            if (date.compareTo(DATE_FORMAT.parse(BOUNDARY_DATE)) >= 0) {
                return "Y";
            } else {
                return "X";
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public double getDistance() {
        return distance;
    }

    public boolean isNormalACanFly() {
        // A已经加班了11天
        if (grandTotalDaysOfA > threshold) {
            return false;
        }
        return normalACanFly;
    }

    public void setNormalACanFly(boolean normalACanFly) {
        this.normalACanFly = normalACanFly;
    }

    public boolean isNormalBCanFly() {
        if (isBrest()) {
            return false;
        }
        return normalBCanFly;
    }

    public void setNormalBCanFly(boolean normalBCanFly) {
        this.normalBCanFly = normalBCanFly;
    }

    public Date getDate() {
        return date;
    }

    /**
     * 获取载重
     *
     * @return
     */
    public int getLoad() {
        Random random = new Random();
        int temp = random.nextInt(101);
        while (temp < 60) {
            temp = random.nextInt(101);
        }
        System.out.println(temp);
        return temp;
    }

}
